Change a template of template drop
If the corridor has
a template drop assigned and now user wants a different template to assign to a
corridor. The below code snippet shows how to achieve this. In below code we
take a first template drop from all TemplateDrops of a corridor and edit its
template.
public bool ChangeTemplateOfTemplateDrop(Corridor corridor)
{
//Change template of first template drop of corridor
//Iterave over all template drops of corridor
foreach (TemplateDrop td in corridor.TemplateDrops)
{
//Template library name
string templateName = "C:\\ProgramData\\Bentley\\OpenRoads Designer CE 10.11\\
Configuration\\Organization-Civil\\_Civil Default Standards - Imperial\\Template Library\\OpenRoadsTemplatesImperial.itl";
//Template path from template library
string templatePath = "Templates\\Rural\\Asphalt Pavt w/ Asphalt Shoulders\\Undivided\\2 Lanes";
//Load a templateof given path from template library
Bentley.CifNET.GeometryModel.SDK.TemplateLibrary templateLibary =
Bentley.CifNET.GeometryModel.SDK.TemplateLibrary.Load(templateName, templatePath);
if (null == templateLibary) return false;
Bentley.CifNET.GeometryModel.SDK.TemplateDefinition templateDefinition =
templateLibary.ActiveTemplate;
if (null == templateDefinition) return false;
//Set the new template to template drop
td.SetTemplate(templateDefinition);
break;
}
return true;
}
The SetTemplate API of Bentley.CifNET.GeometryModel.SDK.TemplateDrop is used to change the template. The parameters required are template library and a new template path from template library. The template path includes the category and subcategories.